<?

if ($DATA['component']['id']) {
	
	$_defaults = array('title' => '', 'keywords' => '', 'description' => '');
	$_record = array('id_data' => D_MB_DATA, 'id_parent' => $DATA['component']['id'], 'assoc' => '');

	$_lang_indep = array();
	$_lang_dep	= array('title', 'keywords', 'description');	// which fields are stored in language variations



	switch (action(array('editor_save'))) {
	
		case 'editor_save':

			$temp = array();
			
			foreach($_lang_indep as $k => $v)
				if (($t = trim(postdata($k))) !== '')
					$temp[] = array_merge($_record, array('name' => $k, 'value' => $t));

			foreach($DATA['langs'] as $lang) {
				foreach($_lang_dep as $name) {
					$t = postdata($name);
					$temp[] = array_merge($_record, array('name' => $name, 'value' => $t[$lang['text']], 'assoc' => $lang['text']));
				}
			}

			dataset('db_delete', tb('data'), "(id_data=".D_MB_DATA.") AND (id_parent={$DATA[component][id]})");
			dataset('db_insert', tb('data'), $temp);
			
			return true;	// end of component edition
	}
	

	$DATA['data'] = array_merge( $_lang_indep, datafetch_array('meta', D_MB_DATA, $DATA['component']['id']));

	foreach($DATA['langs'] as $lang)
		$DATA['data']['data'][$lang['text']] = datafetch_array('meta', D_MB_DATA, $DATA['component']['id'], $lang['text']);

	return false;

} else exit;